package com.io.example.demoparent.mq.config;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import org.springframework.context.annotation.Bean;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @program: demo-project
 * @ClassName RabbitConfig
 * @description:
 * @author: 宠儿
 * @create: 2024−09-09 19:36
 * @Version 1.0
 **/
public class RabbitConfig {

    @Bean
    public Channel rabbitChannel() throws IOException, TimeoutException {
        ConnectionFactory factory=new ConnectionFactory();
        //工厂ip 链接Rabbit队列
        factory.setHost("192.168.164.131");
        //用户名
        factory.setUsername("guest");
        //密码
        factory.setPassword("guest");
        //创建一个信道
        Connection connection = factory.newConnection( );
        //获取信道
        return connection.createChannel( );
    }
}
